<html>
    <head>
    <link rel="stylesheet" href="lmm.css" type="text/css" />
    </head>
<body class="lmm">
<!-- This file is part of the Lisp Machine Manual.  -*-Text-*- -->
<!-- Function Description: Data Type Predicates. > -->
<div class='chapter'>4. Predicates</div>
<p class='cindent'><!-- "predicate" -->
	A <font class="italic">predicate</font> is a function which tests for some condition involving
its arguments and returns the symbol <font class="lisp">t</font> if the condition is true, or
the symbol <font class="lisp">nil</font> if it is not true.

	By convention, the names of predicates usually end in the letter "p" (which
stands for "predicate").  (See [section on naming conventions]).
<p class='cindent'><!-- "naming convention" -->

	The following predicates are for testing data types.  These predicates
return <font class="lisp">t</font> if the argument is of the type indicated by the name of the function,
<font class="lisp">nil</font> if it is of some other type.
<p class='cindent'><!-- "data-type" -->

<div class='defun'><font class='exdent'><font class='funcname'>symbolp <font class='italic' color='purple'>arg</font></font></font><br>
<p class='cindent'><!-- "symbol" -->
<font class="lisp">symbolp</font> returns <font class="lisp">t</font> if its argument is a symbol, otherwise <font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>nsymbolp <font class='italic' color='purple'>arg</font></font></font><br>
<font class="lisp">nsymbolp</font> returns <font class="lisp">nil</font> if its argument is a symbol, otherwise <font class="lisp">t</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>listp <font class='italic' color='purple'>arg</font></font></font><br>
<p class='cindent'><!-- "cons" -->
<font class="lisp">listp</font> returns <font class="lisp">t</font> if its argument is a cons, otherwise <font class="lisp">nil</font>.
<font class="lisp">(listp nil)</font> is <font class="lisp">nil</font> even though <font class="lisp">nil</font> is the empty list.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>nlistp <font class='italic' color='purple'>arg</font></font></font><br>
<font class="lisp">nlistp</font> returns <font class="lisp">t</font> if its argument is anything besides a cons,
otherwise <font class="lisp">nil</font>.
This is the recommended predicate for terminating iterations or recursions
on lists.  It is, in fact, identical to <font class="lisp">atom</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>atom <font class='italic' color='purple'>arg</font></font></font><br>
<p class='cindent'><!-- "atom" -->
The predicate <font class="lisp">atom</font> returns <font class="lisp">t</font> if its argument is not a cons,
otherwise <font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>fixp <font class='italic' color='purple'>arg</font></font></font><br>
<font class="lisp">fixp</font> returns <font class="lisp">t</font> if its argument is a fixnum or a bignum, otherwise
<font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>floatp <font class='italic' color='purple'>arg</font></font></font><br>
<font class="lisp">floatp</font> returns <font class="lisp">t</font> if its argument is a flonum or a small flonum,
otherwise <font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>small-floatp <font class='italic' color='purple'>arg</font></font></font><br>
<font class="lisp">small-floatp</font> returns <font class="lisp">t</font> if <font class="italic">arg</font> is a small flonum, otherwise <font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>bigp <font class='italic' color='purple'>arg</font></font></font><br>
<font class="lisp">bigp</font> returns <font class="lisp">t</font> if <font class="italic">arg</font> is a bignum, otherwise <font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>numberp <font class='italic' color='purple'>arg</font></font></font><br>
<p class='cindent'><!-- "number" -->
<font class="lisp">numberp</font> returns <font class="lisp">t</font> if its argument is any kind of number,
otherwise <font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>stringp <font class='italic' color='purple'>arg</font></font></font><br>
<p class='cindent'><!-- "string" -->
<font class="lisp">stringp</font> returns <font class="lisp">t</font> if its argument is a string, otherwise <font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>arrayp <font class='italic' color='purple'>arg</font></font></font><br>
<p class='cindent'><!-- "array" -->
<font class="lisp">arrayp</font> returns <font class="lisp">t</font> if its argument is an array, otherwise <font class="lisp">nil</font>.
Note that strings are arrays.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>subrp <font class='italic' color='purple'>arg</font></font></font><br>
<font class="lisp">subrp</font> returns <font class="lisp">t</font> if its argument is any compiled code object,
otherwise <font class="lisp">nil</font>.  The Lisp Machine system doesn't use the term "subr",
but the name of this function comes from Maclisp.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>closurep <font class='italic' color='purple'>arg</font></font></font><br>
<p class='cindent'><!-- "closure" -->
<font class="lisp">closurep</font> returns <font class="lisp">t</font> if its argument is a closure, otherwise <font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>locativep <font class='italic' color='purple'>arg</font></font></font><br>
<p class='cindent'><!-- "locative" -->
<font class="lisp">locativep</font> returns <font class="lisp">t</font> if its argument is a locative, otherwise <font class="lisp">nil</font>.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>typep <font class='italic' color='purple'>arg</font></font></font><br>
<font class="lisp">typep</font> is not really a predicate, but it is explained here because it is
used to determine the datatype of an object.  It returns a symbol describing the
type of its argument, one of the following:
.table 3 100
.item :symbol
A symbol.
.item :fixnum
A fixnum.
.item :flonum
A flonum.
.item :small-flonum
A small flonum.
.item :bignum
A bignum.
.item :list
A cons.
.item :string
A string.
.item :array
An array that is not a string.
.item :random
Any built-in data type that does not fit into one of the above categories.
.item <font class="italic">foo</font>
An object of user-defined data-type <font class="italic">foo</font> (any symbol).
See Named Structures, <a href='dfstr.html#named-structure'>this link</a>.
.end_table

See also <font class="lisp">data-type</font>, (data-type-fun).
</div>
.eof
</body>
</html>

